package shiyan;
import java.util.Calendar;

public class CardIDTest {
	private String s;
	public void setCardID(String ss){
		this.s=ss;
	}
	public boolean CardIDlenth(){
		return this.s.length()==18;
	}
	public boolean CardIDVerify(){
		boolean flag=true;
		for(int i=0;i<=16;i++){
			int c=this.s.charAt(i);
			if(c<'0'||c>'9'){
				flag=false;
				break;
			}
		}
		char l=this.s.charAt(17);
		if(!((l>='0'&&l<='9')||(l=='X')||(l=='x'))){
			flag=false;
		}
		return flag;
	}
	public boolean CardIDcheck(){
		String testNum=this.s.substring(0,17)+"0";
		int i=18,wi,ai,sum=0;
		for(i=18;i>=1;i--){
			ai=testNum.charAt(18-i)-48;
			wi=(int)Math.pow(2, i-1)%11;
			sum+=ai*wi;
			//System.out.println("i="+i+",ai="+ai+",wi="+wi+",sum="+sum);
		}
		int mod=sum%11;
		char l[]={'1','0','X','9','8','7','6','5','4','3','2'};
		System.out.println("正确的验证码是："+l[mod]);
		return this.s.toUpperCase().charAt(17)==l[mod];
	}
	public void out(){
		int year,month,day;
		year=Integer.parseInt(this.s.substring(6,10));
		month=Integer.parseInt(this.s.substring(10,12));
		day=Integer.parseInt(this.s.substring(12,14));
		System.out.println("您的生日："+year+"年"+month+"月"+day+"日");
		Calendar cal=Calendar.getInstance();
		int nYear=cal.get(Calendar.YEAR);
		int age=nYear-year;
		int nMonth=cal.get(Calendar.MONTH)+1;
		int nDay=cal.get(Calendar.DAY_OF_MONTH);
		if(nMonth<month)age--;
		if(nMonth==month&&nDay<day)age--;
		if(nMonth==month&&nDay==day)
			System.out.println("生日快乐");
		System.out.println("您的年龄："+age+"岁");
		if(this.s.charAt(16)%2==0){
			System.out.println("您的性别：女性");
		}else{
			System.out.println("您的性别：男性");
		}
	}
	public boolean birthVerify(){
		int day[]={31,29,31,30,31,30,31,31,30,31,30,31};
		int month,da;
		month=Integer.parseInt(this.s.substring(10,12));
		da=Integer.parseInt(this.s.substring(12,14));
		if(!(month>=1&&month<=12)){
			if(!(da>=1&&da<=31)){
				System.out.print("出生月日都有错");
				return false;
			}else{
				System.out.print("出生月份有错");
				return false;
			}
		}else if(!(da>=1&&da<=day[month-1])){
			System.out.print("出生日期有错");
			return false;
		}else{
			return true;
		}


	}

}